//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.Expressions
{
#if DEBUG
        [ContractClass(typeof (RangeReferenceContract))]
#endif
    abstract class RangeReference
    {
#if DEBUG
        [ContractClassFor(typeof (RangeReference))]
        abstract class RangeReferenceContract: RangeReference
        {
            protected override Range GetRange()
            {
                Contract.Ensures(Contract.Result<Range>() != null);
                throw new NotSupportedException();
            }
        }
#endif
        private Range _range;
        private RowColumnGeneration _rowColumnGeneration;
        public abstract Worksheet Worksheet { get;}
        public  Range Range { get
        {
            Contract.Ensures(Contract.Result<Range>() != null);
            if (_range == null || _rowColumnGeneration.LessThan (this.Worksheet.Workbook.RowColumnGeneration))
            {
                _rowColumnGeneration = Worksheet.Workbook.RowColumnGeneration;
                _range = GetRange();

            }
            return _range;
        }
}

            protected abstract Range GetRange();
        public abstract string Label{get;}
        public virtual string FullLabel { get { return Worksheet.SafeName + "!" + Label; } }
        public abstract RangeReference Offset(CellRelativeAddress address);

        internal abstract RangeReference Transposed(Cell target);

            internal abstract RangeReference Projected(Worksheet targetWorksheet);
    }
}
